﻿using Hidistro.Core;
using Hidistro.Core.Enums;
using Hidistro.Entities;
using Hidistro.Entities.Commodities;
using Hidistro.SaleSystem.Catalog;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class wnxd_PinPaiTuiJian : WebControl
    {
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(this.RendHtml());
        }

        public string RendHtml()
        {
            StringBuilder builder = new StringBuilder();
            int categoryId = 0;
            int.TryParse((HttpContext.Current.Handler as System.Web.UI.Page).Request.QueryString["CategoryId"], out categoryId);
            DataTable brandCategories = CategoryBrowser.GetBrandCategories(categoryId, this.maxNum);
            if ((brandCategories != null) && (brandCategories.Rows.Count > 0))
            {
                foreach (DataRow row in brandCategories.Rows)
                {
                    builder.AppendFormat("<div><a href=\"{0}\">", Globals.GetSiteUrls().SubBrandDetails((int)row["BrandId"], row["RewriteName"]));
                    builder.AppendFormat("<img data-original=\"{0}\" border=\"0\" /><p>{1}</p><p class=\"hhh\">{2}</p>", Globals.GetImgUrl(row["Logo"].ToString()), row["BrandName"], row["BrandName"]);
                    builder.AppendFormat("</a></div>");
                }
                builder.Append("<script type=\"text/javascript\">");
                builder.Append("$(\".content4-three\").children(\"div\").hover(function () {");
                builder.Append("$(this).css({ \"margin\": 0, \"border\": \"3px solid #cf1381\", \"overflow\": \"hidden\" }).find(\".hhh\").show().animate({ \"top\": -34, \"height\": 34 }, 300);");
                builder.Append("}, function () {");
                builder.Append("$(this).css({ \"margin\": \"\", \"border\": \"\", \"overflow\": \"\" }).find(\".hhh\").animate({\"height\": 0, \"top\": 0 }, 300, function () { this.style.display = \"none\"; });");
                builder.Append("});</script>");
            }
            return builder.ToString();
        }

        public int maxNum { get; set; }
    }
}
